﻿using AutoMapper;
using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.UserCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.UserHandler
{
    public class GetUserHandler : IRequestHandler<GetUserCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> userRepo;
        private readonly ILogger<GetUserHandler> logger;
        private readonly IMapper mapper;

        public GetUserHandler(IBaseRepository<User> userRepo, ILogger<GetUserHandler> logger, IMapper mapper)
        {
            this.userRepo = userRepo;
            this.logger = logger;
            this.mapper = mapper;
        }

        public Task<APIResult<List<User>>> Handle(GetUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result=new APIResult<List<User>>();
            try
            {
                var model = userRepo.GetAll().ToList();
                result.Code = APIEnum.Success;
                result.Msg = "查询成功";
               
                result.Data=model;
                return Task.FromResult(result);

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
